// components/merchant-result/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { WXPAYMENT_APPLY_STATUS_VALUE } from '../../../constants/payment';
import { saveImage, tipSuccess, tipError } from '../../../common/env';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        resultInfo: {
            type: Object,
            value: {},
        },
    },
    data: {
        WXPAYMENT_APPLY_STATUS_VALUE,
        qrCodePath: '',
    },
    methods: {
        handleGetQrcode(e) {
            const qrCodePath = e.detail;
            this.setData({ qrCodePath });
        },
        handleModify() {
            this.triggerEvent('modify');
        },
        handleComplete() {
            this.triggerEvent('complete');
        },
        handleBack() {
            this.triggerEvent('back');
        },
        async handleDownload() {
            const { qrCodePath } = this.data;
            const flag = await saveImage(qrCodePath);
            flag ? tipSuccess('保存成功！') : tipError('保存失败！');
        },
        handleRefresh() {
            this.triggerEvent('refresh');
        },
    }
})
